//
//  AccountTool.m
//  SenssunLife
//
//  Created by admin on 16/8/31.
//  Copyright © 2016年 Zhongshan Camry Electronic Company Limited. All rights reserved.
//

#import "AccountTool.h"
#import "Account.h"
//#import "AppDelegate.h"
//#import "loginController.h"
#define SENAccountFileName [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"token.data"]
#define tokenExp 7200

@implementation AccountTool

static Account *_account;

+ (void)saveAccount:(Account *)account
{
    [NSKeyedArchiver archiveRootObject:account toFile:SENAccountFileName];
}
+ (Account *)account
{
    if (_account == nil) {
        _account = [NSKeyedUnarchiver unarchiveObjectWithFile:SENAccountFileName];
    }else{
        //延长tokenExpiration的过期时间
        NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];
        _account.tokenExpiration = interval + tokenExp;
    }
    return _account;
}

+(Account *)cleanAccount {
    _account =nil;
    return _account;
}
//+(void)popRootView {
//    UIApplication *application = [UIApplication sharedApplication];
//    AppDelegate *delegate = (AppDelegate *)application.delegate;
//    UIWindow *window = application.keyWindow;
//    window.rootViewController = nil;
//    delegate.nav = [[UINavigationController alloc]initWithRootViewController:[[loginController alloc]init]];
//    [delegate.nav.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
//    [delegate.nav.navigationBar setShadowImage:[[UIImage alloc]init]];
//    [delegate.nav.navigationBar setBarTintColor:SSColorA(57, 181, 172, 255)];
//    delegate.nav.navigationBar.translucent = NO;
//    delegate.nav.navigationBar.hidden = YES;
//    delegate.nav.interactivePopGestureRecognizer.enabled = NO;
//    window.rootViewController =delegate.nav;
//    delegate.tabbar = nil;
//    [window makeKeyAndVisible];
//}
@end
